<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class SystemUser extends BaseModel
{
    protected $name = 'system_user';


    public function setPasswordAttr($value): string
    {
        return password_hash($value, PASSWORD_DEFAULT);
    }

    /**
     * 上传的图片
     * @return \think\model\relation\HasOne
     */
    public function avatarInfo()
    {
        return $this->hasOne(SystemUploadfile::class, 'id', 'avatar');
    }

    /**
     * 通过中间表关联角色.
     */
    public function roles()
    {
        return $this->belongsToMany(SystemRole::class, 'system_user_role', 'role_id', 'user_id');
    }
}
